#include <stdio.h>
#include "boy.h"

enum {BOY_BORN, LAST_SIGNAL};
static gint boy_signals[LAST_SIGNAL] = {0};
static void boy_cry(void);
static void boy_born(void);

G_DEFINE_TYPE(Boy, boy, G_TYPE_OBJECT);

static void boy_init(Boy *boy)
{
    boy->age = 0;
    boy->name = "none";
    boy->cry = boy_cry;
    puts("boy init finished.");
}
static void boy_class_init(BoyClass *boyclass)
{
    boyclass->boy_born = boy_born;
    boy_signals[BOY_BORN] = g_signal_new("boy_born",
                BOY_TYPE,
                G_SIGNAL_RUN_FIRST,
                G_STRUCT_OFFSET(BoyClass,boy_born),
                NULL,NULL,
                g_cclosure_marshal_VOID__VOID,
                G_TYPE_NONE, 0, NULL);
    puts("BoyClass init finished.");
}

Boy *boy_new(void)
{
    Boy *boy;
    boy = g_object_new(BOY_TYPE, NULL);
    g_signal_emit(boy,boy_signals[BOY_BORN],0);
    return boy;
}


Boy *boy_new_with_pr(gint pr)
{
    Boy *boy;
    boy = g_object_new(BOY_TYPE, "pr", 0, NULL);
    return boy;
}

int boy_get_age(Boy *boy)
{
    return boy->age;
}

void boy_set_age(Boy *boy, int age)
{
    boy->age = age;
}

void boy_set_name(Boy *boy, char *name)
{
    boy->name = name;
}

static void boy_cry (void)
{
    g_print("The Boy is crying ......\n");
}
static void boy_born(void)
{
    g_print("Message : A boy was born .\n");
}
void  boy_info(Boy *boy)
{
    g_print("The Boy name is %s\n", boy->name);
    g_print("The Boy age is %d\n", boy->age);
}
